﻿#region License
/*
Copyright (c) <2012> <Nercoding>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Original Code by Gastric of Dawnsong
 */
#endregion
using System;
using System.Diagnostics;

namespace AC2_MultiClient.Managers
{
    /// <summary>
    /// This class represents a logged in user
    /// </summary>
    public class Client
    {
        /// <summary>
        /// The process
        /// </summary>
        public Process ClientProcess { get; set; }
        /// <summary>
        /// The username
        /// </summary>
        public string ClientName { get; set; }
        /// <summary>
        /// The directory location used from Config.xml
        /// </summary>
        public string UsedDir { get; set; }
        /// <summary>
        /// A timer to show how long this client has been logged in
        /// </summary>
        public Stopwatch LoggedInTime { get; set; }
        /// <summary>
        /// The Window Handle
        /// </summary>
        public IntPtr WindowHandle { get; set; }
        /// <summary>
        /// Creates a client
        /// </summary>
        /// <param name="Username">The username</param>
        /// <param name="UsedDirectory">a directory location from config.xml</param>
        /// <param name="Usedprocess">the ac2client process</param>
        public Client(string Username, string UsedDirectory, Process Usedprocess)
        {
            this.ClientName = Username;
            this.UsedDir = UsedDirectory;
            this.ClientProcess = Usedprocess;
            LoggedInTime = new Stopwatch();
            LoggedInTime.Start();
        }
        /// <summary>
        /// Returns the amount of time this client has been logged into the game
        /// </summary>
        /// <returns></returns>
        public string GetLoggedInTime()
        {
            string logged = "Logged in for ";
            if (LoggedInTime.Elapsed.Days > 0) { logged += LoggedInTime.Elapsed.Days+" Day(s) "; }
            if (LoggedInTime.Elapsed.Hours > 0) { logged += LoggedInTime.Elapsed.Hours + " Hour(s) "; }
            if (LoggedInTime.Elapsed.Minutes > 0) { logged += LoggedInTime.Elapsed.Minutes + " Minute(s) "; }
            if (LoggedInTime.Elapsed.Seconds > 0) { logged += LoggedInTime.Elapsed.Seconds + " Second(s)"; }
            return logged;
        }
    }
}
